package org.eduapp.trains.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class UtilsCollection {
	
	public static Object[] List2Array(List<Object> oList) {   
        Object[] oArray = oList.toArray(new Object[] {});   
        return oArray;   
    }   
  
    public static Object[] Set2Array(Set<Object> oSet) {   
        Object[] oArray = oSet.toArray(new Object[] {});   
        return oArray;   
    }   
  
    public static <T extends Object> List<T> Set2List(Set<T> oSet) {   
        List<T> tList = new ArrayList<T>(oSet);   
        return tList;   
    }   
  
    public static <T extends Object> List<T> Array2List(T[] tArray) {   
        List<T> tList = Arrays.asList(tArray);   
        return tList;   
    }   
  
    public static <T extends Object> Set<T> List2Set(List<T> tList) {   
        Set<T> tSet = new HashSet<T>(tList);   
        return tSet;   
    }   
  
    public static <T extends Object> Set<T> Array2Set(T[] tArray) {   
        Set<T> tSet = new HashSet<T>(Arrays.asList(tArray));   
        return tSet;   
    } 
    
    public static <T extends Object, K extends Object> Map<T, K> MapClone(Map<T, K> src){
    	if(src != null && src.size() > 0){
    		Map<T, K> target = new TreeMap<T, K>();
    		for(Iterator<T> keyIt = src.keySet().iterator(); keyIt.hasNext();){
    			T key = keyIt.next();
    			target.put(key, src.get(key));
    		}
    		return target;
    	}
    	return null;
    }
    
}
